﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class Admin_HelpNava_Nava : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    public void PopulateHeilNav()
    {
        Lv_DaoHang.DataSource = HelpNava.GetAll();
        Lv_DaoHang.DataBind();
    }
    protected void btnAdd_Click(object sender, EventArgs e)
    {
        HelpNava objHelpNava = new HelpNava();
        objHelpNava.Title = txtBiaoTi.Text;
        if (fuLogo.HasFile)
        {
            objHelpNava.ImgSrc = DongDong.Common.Misc.UploadFile(fuLogo, "/Resource/HelpNav/", ".gif.bmp.psd.jpeg.jpg.png");
        }
        else
        {
            objHelpNava.ImgSrc = "no_image.jpg";
        }
        objHelpNava.Rank = System.DateTime.Now;
        objHelpNava.Add();
        Page.ClientScript.RegisterStartupScript(this.GetType(), "success1", "<script>alert('添加成功')</script>");
        PopulateHeilNav();
    }
    protected void Lv_DaoHang_ItemCanceling(object sender, ListViewCancelEventArgs e)
    {
        Lv_DaoHang.EditIndex = -1;
        PopulateHeilNav();
    }
    protected void Lv_DaoHang_ItemDeleting(object sender, ListViewDeleteEventArgs e)
    {
        HelpNava.Delete(DongDong.Common.Misc.ConvertToInt(Lv_DaoHang.DataKeys[e.ItemIndex].Value));
        PopulateHeilNav();
    }
    protected void Lv_DaoHang_ItemUpdating(object sender, ListViewUpdateEventArgs e)
    {
        int NavID = DongDong.Common.Misc.ConvertToInt(Lv_DaoHang.DataKeys[e.ItemIndex].Value);
        HelpNava objType = HelpNava.Get(NavID);
        var item = Lv_DaoHang.Items[e.ItemIndex];
        TextBox txtEditTitle = (TextBox)item.FindControl("txtEditTitle");
        objType.Title = txtEditTitle.Text;

        FileUpload fuEditLogo = (FileUpload)item.FindControl("fuEditLogo");
        if (fuEditLogo.HasFile)
        {
            objType.ImgSrc = DongDong.Common.Misc.UploadFile(fuEditLogo, "/Resource/HelpNav/", ".gif.bmp.psd.jpeg.jpg.png");
        }
        objType.Rank = System.DateTime.Now;

        objType.Update();
        Lv_DaoHang.EditIndex = -1;
        PopulateHeilNav();
    }
    protected void Lv_DaoHang_ItemEditing(object sender, ListViewEditEventArgs e)
    {
        Lv_DaoHang.EditIndex = e.NewEditIndex;
        PopulateHeilNav();
    }
    protected void Lv_DaoHang_PagePropertiesChanged(object sender, EventArgs e)
    {
        PopulateHeilNav();
    }
    protected void Pager_PreRender(object sender, EventArgs e)
    {
        if (Lv_DaoHang.Items.Count == 0)
            PopulateHeilNav();
    }
    protected void Lv_DaoHang_ItemCommand(object sender, ListViewCommandEventArgs e)
    {
        if (e.CommandName == "Up")
        {
            int KeyID = DongDong.Common.Misc.ConvertToInt(e.CommandArgument);
            HelpNava obj = HelpNava.Get(KeyID);
            if (obj != null)
            {
                obj.Rank = System.DateTime.Now;
                obj.Update();
            }
            PopulateHeilNav();
        }
    }
}